const gulp = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const connect = require("gulp-connect");
const sourcemaps = require("gulp-sourcemaps");

gulp.task("copyHTML",done=>{
    gulp.src("*.html").pipe(gulp.dest("dist")).pipe(connect.reload());
    done();
})

gulp.task("sass",done=>{
    gulp.src("sass/index.scss")
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(sourcemaps.write("./"))
    .pipe(gulp.dest("dist/css"))
    .pipe(connect.reload());
    done()
})

gulp.task("server",done=>{
    connect.server({
        root:"dist",
        livereload:true
    })
    done();
});

gulp.task("watch",done=>{
    gulp.watch("*.html",gulp.series("copyHTML"))
    gulp.watch("sass/*.scss",gulp.series("sass"))
    done()
});

gulp.task("default",gulp.series("server","watch"));